luci-mod-network: Correctly encode/decode ech field in HTTPS record
authorAnya Lin <[email protected]>
Thu, 25 Sep 2025 16:59:01 +0000 (00:59 +0800)
committerPaul Donald <[email protected]>
Mon, 29 Sep 2025 16:26:09 +0000 (18:26 +0200)
Signed-off-by: Anya Lin <[email protected]>
modules/luci-mod-network/htdocs/luci-static/resources/tools/dnsrecordhandlers.js

index 6c5922a5a633e15b3a1ea1183179b56c4deffb47..7d7f236088dcc56810a764e29938e80eb09966b4 100644 (file)
@@ -163,6 +163,7 @@ return baseclass.extend({
                                return keys.map(n => [(n >> 8) & 0xff, n & 0xff]).flat();
 
                        case 'ech': // Assume ech is in base64
+                               return Array.prototype.map.call(atob(value), c => c.charCodeAt(0)); // OR Uint8Array.fromBase64(value)
                        case 'alpn':
                                /* (RFC 9460 ยง7.1.1 The wire-format value for "alpn" consists of
                                at least one alpn-id prefixed by its length as a single octet */
@@ -320,6 +321,7 @@ return baseclass.extend({
                                return keys.join(',');
 
                        case 'ech':
+                               return btoa(String.fromCharCode(...buf)); // OR buf.toBase64()
                        case 'alpn': {
                                let pos = 0, result = [];
                                while (pos < buf.length) {